﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Data;
using System.Web.UI.Design;

namespace jQuery.WebControls.RocketDock
{
    class RocketDockDesigner : ControlDesigner
    {
        protected RocketDockMenu menu;

        public override string GetDesignTimeHtml()
        {
            menu = (RocketDockMenu)Component;

            if (menu.Icons.Count == 0)
            {
                for (int i = 0; i < 2; i++)
                {
                    menu.Icons.Add(new Icono());
                }              
            }
            return generarHtml();
        }

        private string generarHtml()
        {
            StringWriter sw = new StringWriter();
            HtmlTextWriter tw = new HtmlTextWriter(sw);
            ImageButton imgAux;
            Panel p = new Panel();
            if (menu.Height != null)
                p.Height = menu.Height;
            if (menu.Width != null)
            {
                p.Width = menu.Width;
                p.Style.Add("margin-left", "20px");
            }
            p.HorizontalAlign = HorizontalAlign.Center;            
            for (int i = 0; i < menu.Icons.Count; i++)
            {
                imgAux = new ImageButton();
                imgAux.ImageUrl = menu.Icons[i].ImageUrl.Replace("~/", "");
                imgAux.Width = menu.MinimumWidth;
                p.Controls.Add(imgAux);
                //imgAux.RenderControl(tw);                
            }
            p.RenderControl(tw);
            //tw.Write("</div>");
            return sw.ToString();
        }
    }
}
